<?php
class C_staff extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_staff');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			case 'DEACTIVATE' :
				$this->_deactivate();
				break;
			default :
				$this->load->view('app/v_staff');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['staff_nama'] = nosql_post("staff_nama");
		$data['staff_insert_date'] = nosql_post("staff_insert_date");
		echo $this->m_staff->_list($data);
	}
	
	function _insert(){
		$data = array(
			'staff_nama' => $this->input->post('staff_nama'), 
			'staff_insert_date' => $this->input->post('staff_insert_date'), 
			  
			'staff_insert_user'	=>$_SESSION[SESSION_USERID],
			'staff_insert_date'=> date("Y-m-d h:i:s"));
		$this->m_staff->_insert($data);
		echo 1;
	}
	
	function _update(){
		$staff_id = $this->input->post('staff_id');
		$data = array(
			'staff_nama' => $this->input->post('staff_nama'), 
			'staff_insert_date' => $this->input->post('staff_insert_date'), 
			
			'staff_update_user'	=> $_SESSION[SESSION_USERID],
			'staff_update_date'=> date("Y-m-d h:i:s"));
		$this->m_staff->_update($data,$staff_id);
		echo 1;
 	}
	
	function _delete(){
		$staff_id= $this->input->post('staff_id');
		$this->m_staff->_delete($staff_id);
		echo 1;
	}
	
	function _deactivate(){
		$staff_id= $this->input->post('staff_id');
		$data = array(
			'staff_active' => 'n'
		);
		$this->m_staff->_deactivate($data,$staff_id);
		echo 1;
	}
}